//
// afix_stack.h
//

#ifndef _CHLDS_STACK_H_
#define _CHLDS_STACK_H_

#include "chlds_type.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct _TStack
{
    void*   base;
    sint32  used;
    sint32  elen;
    sint32  size;
} TStack;


sint32 stack_create(TStack* pStack, const sint32 elen);

sint32 stack_release(TStack* pStack);

sint32 stack_push(TStack* pStack, const void* p);

void* stack_pop(TStack* pStack);

sint32 stack_used(const TStack* pStack);


#define STACK_CREATE(_pStack, _type)            stack_create(_pStack, sizeof(_type))
#define STACK_RELEASE(_pStack)                  stack_release(_pStack)
#define STACK_PUSH(_pStack, _v)                 stack_push(_pStack, &(_v))
#define STACK_POP(_pStack, _type)               (*(_type*)stack_pop(_pStack))
#define STACK_USED(_pStack)                     stack_used(_pStack)

#ifdef __cplusplus
}
#endif

#endif // _AFIX_STACK_H_
